package com.lyy.service.impl;

import com.lyy.entity.OrderMessage;
import com.lyy.service.OrderService;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Liangyaoyun
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private RocketMQTemplate rocketMQTemplate;
    @Override
    public void insert() {
        System.out.println("下单成功!");
        // 组装RocketMQ消息数据
        OrderMessage orderMessage = new OrderMessage();
        orderMessage.setUsername("姜英博");
        orderMessage.setPhone("18210210122");
        orderMessage.setSn("OD18169198681681684684");
        orderMessage.setTotalFee(5321.05);

        // 将RocketMQ消息数据发送到MQ中
        rocketMQTemplate.convertAndSend("order-topic:order-tag", orderMessage);

        System.out.println("向MQ发送订单成功消息！");

    }
}
